package com.wish.handjdkProxy;

import com.wish.inter.IPerson;

import java.lang.reflect.Method;

/**
 * @Author: suliucheng
 * @Date: 2021/2/28 21:14
 * @Description:
 */
public class GPMeiPo implements GPInvocationHandler{


    private IPerson target;

    /**
     * 获取被代理人的个人资料
     * @param target
     * @return
     * @throws Exception
     */
    public Object getInstance(IPerson target) throws Exception {
        this.target = target;
        Class clazz = target.getClass();
        System.out.println("被代理对象的class是："+ clazz);
        return GPProxy.newProxyInstance(new GPClassLoader(), clazz.getInterfaces(), this);

    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆!");
        System.out.println("开始信息海选");
        System.out.println("-------------");
        method.invoke(this.target, args);
        System.out.println("-------------");
        System.out.println("如果合适的话，就准备办事");
        return null;
    }
}
